package com.it.xml.plic.myenum;

/**
 * @author げっしょく
 * @date 2021/8/11
 */
public class Test1 {
    public static void main(String[] args) {
        //String name()	获取枚举项的名称
        String name = Fruits.ORANGE.name();
        System.out.println(name);
        //int ordinal()	返回枚举项在枚举类中的索引值
        int ordinal = Fruits.ORANGE.ordinal();
        int ordina2 = Fruits.BANANA.ordinal();
        int ordina3 = Fruits.APPLE.ordinal();
        int ordina4 = Fruits.POMELO.ordinal();
        System.out.println(ordinal);
        System.out.println(ordina2);
        System.out.println(ordina3);
        System.out.println(ordina4);
        //int compareTo(E  o)	比较两个枚举项，返回的是索引值的差值
        int i = Fruits.BANANA.compareTo(Fruits.ORANGE);
        System.out.println(i);
        //String toString()	返回枚举常量的名称
        String s = Fruits.ORANGE.toString();
        System.out.println(s);
        //static <T> T  valueOf(Class<T> type,String  name)	获取指定枚举类中的指定名称的枚举值
        Fruits orange = Fruits.valueOf(Fruits.class, "ORANGE");
        System.out.println(orange);
        System.out.println(Fruits.ORANGE == orange);
        //values()	获得所有的枚举项
        Fruits[] values = Fruits.values();
        for (Fruits value : values) {
            System.out.println(value);
        }
    }
}
